import {iVisualComponentActionData, RenderNode} from "../../packages/utils/types.base";
import {iProcessActionRender} from "../../packages/createVisualEditorUser/createVisualEditorAction/createVisualEditorActionRender";

/**
 * 预定义动作渲染
 * @author  韦胜健
 * @date    2022/2/6 23:37
 */
export const predefineActionRender: iProcessActionRender = ({registryActionRender}) => {

    const openFail = (e: any) => {
        e.stopPropagation()
        e.preventDefault()
        alert('当前工程无法跳转页面，请在nuxt或者next工程中使用跳转功能')
    }

    registryActionRender(
        '@@fixed',
        (data: iVisualComponentActionData, content: RenderNode, attrs: any) => (
            <a href={data.data} {...attrs}>
                {content}
            </a>
        )
    )

    registryActionRender(
        'pdp',
        (data: iVisualComponentActionData, content: RenderNode, attrs: any) => (
            <a href={`pdp/${data.data.id}`} {...attrs} onClick={openFail}>
                {content}
            </a>
        ),)

    registryActionRender(
        'category',
        (data: iVisualComponentActionData, content: RenderNode, attrs: any) => (
            <a href={`plp?category=${data.data.code}`} {...attrs} onClick={openFail}>
                {content}
            </a>
        ),
    )

    /*registryActionRender(
        'activity',
        (data: iVisualComponentActionData, content: RenderNode, attrs: any) => (
            <a href={`activity?category=${data.data.code}`} {...attrs} onClick={(e) => {
                openFail(e)
                !!attrs.onClick && attrs.onClick(e)
            }}>
                {content}
            </a>
        ),
    )*/
}
